package com.cloud.utils;

import cn.hutool.core.util.StrUtil;
import com.cloud.common.domain.Result;
import com.cloud.entity.SysNotice;
import com.cloud.enums.NoticeMode;
import com.cloud.service.FeignMessageService;

import java.util.Map;

/**
 * 消息发送工具
 *
 * @author yzj
 */
public class NoticeMessage {

    /**
     * 发送系统消息
     */
    public static Result sysNotice(Integer noticeType, String title, String content, String userIds) {
        SysNotice notice = new SysNotice();
        notice.setSysCode(SecurityUtils.getSysCode());
        notice.setNoticeType(noticeType);
        notice.setSendType(NoticeMode.SYSTEM.getCode());
        notice.setNoticeTitle(title);
        notice.setNoticeContent(content);
        notice.setUserIds(userIds);
        return SpringUtils.getBean(FeignMessageService.class).saveInNotice(notice);
    }

    public static Result sysNotice(Integer noticeType, String title, String content, Long userId) {
        SysNotice notice = new SysNotice();
        notice.setSysCode(SecurityUtils.getSysCode());
        notice.setNoticeType(noticeType);
        notice.setSendType(NoticeMode.SYSTEM.getCode());
        notice.setNoticeTitle(title);
        notice.setNoticeContent(content);
        notice.setUserIds(String.valueOf(userId));
        return SpringUtils.getBean(FeignMessageService.class).saveInNotice(notice);
    }

    /**
     * 发送短信消息
     */
    public static Result smsNotice(Integer noticeType, String title, String content, String userIds) {
        SysNotice notice = new SysNotice();
        notice.setSysCode(SecurityUtils.getSysCode());
        notice.setNoticeType(noticeType);
        notice.setSendType(NoticeMode.SMS.getCode());
        notice.setNoticeTitle(title);
        notice.setNoticeContent(content);
        notice.setUserIds(userIds);
        return SpringUtils.getBean(FeignMessageService.class).saveInNotice(notice);
    }

    /**
     * 发送微信消息
     */
    public static Result weChatNotice(Integer noticeType, String title, String content, String userIds) {
        SysNotice notice = new SysNotice();
        notice.setSysCode(SecurityUtils.getSysCode());
        notice.setNoticeType(noticeType);
        notice.setSendType(NoticeMode.WECHAT.getCode());
        notice.setNoticeTitle(title);
        notice.setNoticeContent(content);
        notice.setUserIds(userIds);
        return SpringUtils.getBean(FeignMessageService.class).saveInNotice(notice);
    }

    /**
     * 发送邮件消息
     */
    public static Result sendMallNotice(Integer noticeType, String title, String content, String userIds) {
        SysNotice notice = new SysNotice();
        notice.setSysCode(SecurityUtils.getSysCode());
        notice.setNoticeType(noticeType);
        notice.setSendType(NoticeMode.EMAIL.getCode());
        notice.setNoticeTitle(title);
        notice.setNoticeContent(content);
        notice.setUserIds(userIds);
        return SpringUtils.getBean(FeignMessageService.class).saveInNotice(notice);
    }

    /**
     * 发送浙政钉消息
     */
    public static Result sendZzdNotice(Integer noticeType, String title, String content, String userIds) {
        SysNotice notice = new SysNotice();
        notice.setSysCode(SecurityUtils.getSysCode());
        notice.setNoticeType(noticeType);
        notice.setSendType(NoticeMode.DING_TALK_MSG.getCode());
        notice.setNoticeTitle(title);
        notice.setNoticeContent(content);
        notice.setUserIds(userIds);
        return SpringUtils.getBean(FeignMessageService.class).saveInNotice(notice);
    }

    /**
     * 获取消息内容
     *
     * @param template 消息模板
     * @param map      消息模板参数
     * @return
     */
    public static String getMessageContent(String template, Map<String, Object> map) {
        return StrUtil.format(template, map);
    }

}
